home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10427 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: floats in borland C++ 4.5
  5. Date: Sun, 17 Mar 96 18:19:20 GMT
  6. Organization: none
  7. Message-ID: <827086760snz@genesis.demon.co.uk>
  8. References: <4if2ec$scg@bertrand.ccs.carleton.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4if2ec$scg@bertrand.ccs.carleton.ca>
  15.            abelo@chat.carleton.ca "Andrew Belo" writes:
  16.  
  17. >
  18. >When ever I write a program that uses float or doubles I get errors such
  19. >as floating point library not linked or stack fault.  These errors do not
  20. >happen when I am compiling my files the happen when I am actualy running
  21. >the program!  I will post some code to give you an example.  WHen running
  22. >this code it gives the following message
  23. >Floating point error: Stack
  24. >fault.  Abnormal termination.
  25. >
  26. >   when this function is called:
  27. >
  28. >void bubblesort( double *dblarray, int numberOfElements)
  29. >
  30. >{
  31. >        int top, search, temp; 
  32. >
  33. >        for( top = 0; top < numberOfElements -1; top++)
  34. >                for(search = top +1; search < numberOfElements; search++)
  35. >                        if(dblarray[search] > dblarray[top])
  36. >                        {
  37. >                                temp = dblarray[search];
  38. >                                dblarray[search] = dblarray[top];
  39. >                                dblarray[top] = temp; 
  40. >                        }
  41. >}
  42.  
  43. Firstly this isn't a bubble sort (e.g. bubble sort always compares and swaps
  44. adjacent elements), it is an exchange sort. Do you have any reason not to
  45. use the standard library qsort() function - it is likely to be much more
  46. efficient.
  47.  
  48. In the code you are trying to exchange double quantities using an int
  49. temporary variable - make temp a double.
  50.  
  51. For 'floating point library not linked' or similar see the FAQ (which
  52. actually directs you to the comp.os.msdos.progarmmer FAQ in this case).
  53.  
  54. There is nothing else obviously wrong however the problem may be in how you
  55. call it. Post a minimal but *complete* program (i.e. one that we can
  56. compile and execute) demonstrating the problem.
  57.  
  58. -- 
  59. -----------------------------------------
  60. Lawrence Kirby | fred@genesis.demon.co.uk
  61. Wilts, England | 70734.126@compuserve.com
  62. -----------------------------------------
  63.